package controllers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.OwnerDomain;

import models.OwnerDomainModel;

public class DeleteOwnerSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		String domainName = (String) request.getParameter("id");
		OwnerDomainModel oData = OwnerDomainModel.getInstance();
		OwnerDomain ownerDomain = oData.getOwnerDomain(domainName);
		if (ownerDomain != null && request.getUserPrincipal().getName().equalsIgnoreCase(ownerDomain.getUsername())) {
			oData.delete(ownerDomain);
		}
		
		response.sendRedirect("/profile/view");
	}
}
